Paraguayan Chaco Forest Cover & Loss

Departments Forest Cover

Code
# non interactive 

# ggplot(data = dept_fc, aes(x = year, y = area_ha_round, group = nom_dpto, color = nom_dpto)) +
#   geom_line(size = 1) +
#   labs(title = "Forest Cover Over the Years",
#        x = "Year",
#        y = "Forest Cover Area (ha)",
#        color = "Department") +
#   theme_minimal() +
#   theme(legend.position = "bottom")
# # Convert year column to factor to preserve the order
# dept_fc$year <- as.factor(dept_fc$year)


# Create an interactive forest cover plot over the years
plot_ly(data = dept_fc, x = ~year, y = ~area_ha_round, color = ~nom_dpto, type = "scatter", mode = "lines") %>%
  layout(title = "Chaco Departments Forest Cover Over the Years",
         xaxis = list(title = "Year", x = 0.5),
         yaxis = list(title = "Forest Cover Area (ha)"),
         legend = list(title = "Department"))

Districts Forest Cover

Code
# Convert year column to factor to preserve the order
dist_fc$year <- as.factor(dist_fc$year)

plot_ly(data = dist_fc, x = ~year, y = ~area_ha_round, color = ~nom_dist, type = "scatter", mode = "lines") %>%
  layout(title = list(text = "Chaco Districts Forest Cover Over the Years", x = 0.5), 
         xaxis = list(title = "Year", title_standoff = 30), 
         yaxis = list(title = "Forest Cover Area (ha)"),
         legend = list(title = "Department",  
                      bgcolor = "white",                     
                      itemsizing = "constant",               
                      itemwidth = 60,                        
                      margin = list(l = 0, r = 0, t = 0, b = 0)))

Departments Forest Loss

Code
# Create an interactive forest cover plot over the years
plot_ly(data = dept_fl, x = ~year_range, y = ~area_ha_round, color = ~nom_dpto, type = "scatter", mode = "lines") %>%
  layout(title = "Chaco Departments Forest Loss Over the Years",
         xaxis = list(title = "Year", x = 0.5),
         yaxis = list(title = "Forest Lorest Loss Area (ha)"),
         legend = list(title = "Department"))

Districts Forest Loss

Code
# Create an interactive forest cover plot over the years
plot_ly(data = dist_fl, x = ~year_range, y = ~area_ha_round, color = ~nom_dist, type = "scatter", mode = "lines") %>%
  layout(title = "Chaco Districts Forest Loss Over the Years",
         xaxis = list(title = "Year", x = 0.5),
         yaxis = list(title = "Forest Loss Area (ha)"),
         legend = list(title = "District"))

Maps

2000 Forest Cover Percentage by Department

Code
# Leaflet map (hover)


# Reproject to long-lat CRS (assuming original CRS is in meters)
dept_fc_w_geom_2000 <- st_transform(dept_fc_w_geom_2000, crs = st_crs(4326)) 

# Set the latitude and longitude for Paraguay
paraguay_lat <- -23.442503
paraguay_lon <- -58.443832

# Create the leaflet map
map <- leaflet(dept_fc_w_geom_2000) %>%
  addTiles(urlTemplate = "https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png") %>%
  setView(lat = paraguay_lat, lng = paraguay_lon, zoom = 6) %>%  # Set the view to Paraguay
  addPolygons(fillColor = ~colorNumeric(palette = "YlGnBu", domain = dept_fc_w_geom_2000$percent_fc_round)(percent_fc_round),
              fillOpacity = 0.7,
              weight = 1,
              color = "black",
              label = ~paste0(dept_fc_w_geom_2000$nom_dpto.x," Forest Cover: ", 
                              dept_fc_w_geom_2000$percent_fc_round, "%"),
              labelOptions = labelOptions(noHide = FALSE, textOnly = FALSE)
              ) %>%
  addLegend(position = "topright",
            pal = colorNumeric(palette = "YlGnBu", domain = dept_fc_w_geom_2000$percent_fc_round),
            values = dept_fc_w_geom_2000$percent_fc_round,
            title = "% Forest Cover",
            opacity = 0.7) 

# tiles 
# https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg

# Display the map
map
Code
# Leaflet (click) different aesthetics
# Reproject to long-lat CRS (assuming original CRS is in meters)
dept_fc_w_geom_2000 <- st_transform(dept_fc_w_geom_2000, crs = st_crs(4326)) 

# Set the latitude and longitude for Paraguay
paraguay_lat <- -23.442503
paraguay_lon <- -58.443832

# Create the leaflet map
map <- leaflet(dept_fc_w_geom_2000) %>%
  addTiles(urlTemplate = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png") %>%
  setView(lat = paraguay_lat, lng = paraguay_lon, zoom = 6) %>%  # Set the view to Paraguay
  addPolygons(fillColor = ~colorNumeric(palette = "Greens", domain = dept_fc_w_geom_2000$percent_fc_round)(percent_fc_round),
              fillOpacity = 0.7,
              weight = 1,
              color = "black",
              popup = paste("<strong>Department: </strong>", dept_fc_w_geom_2000$nom_dpto.x,
                            "<br><strong>% Forest Cover: </strong>", dept_fc_w_geom_2000$percent_fc_round, "%")) %>%
  addLegend(position = "topright",
            pal = colorNumeric(palette = "Greens", domain = dept_fc_w_geom_2000$percent_fc_round),
            values = dept_fc_w_geom_2000$percent_fc_round,
            title = "% Forest Cover",
            opacity = 0.7)

map

2000 Forest Cover Percentage by District

Code
# Reproject to long-lat CRS (assuming original CRS is in meters)
dist_fc_w_geom_2000 <- st_transform(dist_fc_w_geom_2000, crs = st_crs(4326)) 

# Set the latitude and longitude for Paraguay
paraguay_lat <- -23.442503
paraguay_lon <- -58.443832

# Create the leaflet map
dist_fc_2000_map <- leaflet(dist_fc_w_geom_2000) %>%
  addTiles(urlTemplate = "https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png") %>%
  setView(lat = paraguay_lat, lng = paraguay_lon, zoom = 6) %>%  # Set the view to Paraguay
  addPolygons(fillColor = ~colorNumeric(palette = "YlGnBu", domain = dist_fc_w_geom_2000$percent_fc_round)(percent_fc_round),
              fillOpacity = 0.7,
              weight = 1,
              color = "black",
              popup = paste("<strong>District: </strong>", dist_fc_w_geom_2000$nom_dist,
                            "<br><strong>% Forest Cover: </strong>", dist_fc_w_geom_2000$percent_fc_round, "%")) %>%
  addLegend(position = "topright",
            pal = colorNumeric(palette = "YlGnBu", domain = dist_fc_w_geom_2000$percent_fc_round),
            values = dist_fc_w_geom_2000$percent_fc_round,
            title = "% Forest Cover",
            opacity = 0.7)

# Display the map
dist_fc_2000_map